/**
*bts
*/ 

var	BTSDS;
var BTSFormPanel;
function doPowerBoxDelete(id)
{
	Ext.MessageBox.confirm('确认删除', '确认删除该信息?', 
	function(btn) {
		if(btn == 'yes') // 选中了是按钮	
		{
			JBTSWeb.deleteBTSNewBO(id,function(data)
			{
				if(data)
				{ 
					Ext.Msg.alert('成功',"操作成功！"); 
					BTSDS.load({params:{start:0,limit:17,'<%=Constant.BTS_CODE%>':'<%=strbtscode%>'}});	 
					BTSFormPanel.getForm().reset();			
				}else
				{
					Ext.Msg.alert("失败","操作失败!");
				}
			})
		}
	})	
}


Ext.onReady(function(){  
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';

	var BTSType = Ext.data.Record.create([								
							   {name: 'id', type: "string"},
							   {name: 'btsname', type: "string"},
							   {name: 'frequency', type: "string"},
							   {name: 'btscode', type: "string"},
							   {name: 'BSC', type: "string"},
							   {name: 'manufacturer', type: "string"},
							   {name: 'cabinet',  type: 'string'},
							   {name: 'primdevicetype', type: "string"},
							   {name: 'btscfg', type: "string"},
							   {name: 'frequencyNum', type: 'string'},
							   {name: 'combinerType', type: 'string'},							
							   {name: 'combinerNum',  type: 'string'},
							   {name: 'primContrmodel',  type: 'string'},
							   {name: 'primContrNum',  type: 'string'},
							   {name: 'powerPanelType',  type: 'string'},
							   {name: 'powerPanelNum',  type: 'string'},
							   {name: 'powerType',  type: 'string'},							   
							   {name: 'ele2Mnum',  type: 'string'},
							   {name: 'registtime',  type: 'date'},
							   {name: 'antennaType',  type: 'string'},
							   {name: 'antennaFac',  type: 'string'},
							   {name: 'antennaNum',  type: 'string'},
							   {name: 'antennaGain',  type: 'string'},
							   {name: 'antennaDirect',  type: 'string'},
							   {name: 'antennaPolar',  type: 'string'},
							   {name: 'antennaHeight',  type: 'string'},
							   {name: 'antennaPre',  type: 'string'},
							   {name: 'antennaAngle',  type: 'string'},
							   {name: 'antennaPitchAngle',  type: 'string'},
							   {name: 'feederType',  type: 'string'},
							   {name: 'other1',  type: 'string'},
							   {name: 'other2',  type: 'string'},							   
							   {name: 'other3',  type: 'string'},
							   {name: 'other4',  type: 'string'},
							   {name: 'IDUType',  type: 'string'},
							   {name: 'IDUNum',  type: 'string'},
							   {name: 'ODUType',  type: 'string'},
							   {name: 'ODUNum',  type: 'string'},
							   {name: 'refreshtime',  type: 'string'},
							   {name: 'memo',  type: 'string'}
						 ]); 
	var BTSCM = new Ext.grid.ColumnModel(
			[
				new Ext.grid.CheckboxSelectionModel({singleSelect: true}), 	            
				{header: "流水号", sortable: true, dataIndex: 'id',align:'left'},
				{header: "基站编号", sortable: true, dataIndex: 'btscode',align:'left'},
				{header: "基站名称",  sortable: true, dataIndex: 'btsname',align:'left'},	
				{header: "使用频段",  sortable: true, dataIndex: 'frequency',align:'left'},	 	
				{header: "厂家",  sortable: true, dataIndex: 'manufacturer',align:'left'}, 
				{header: "主设备类型",  sortable: true, dataIndex: 'primdevicetype',align:'left'}			
			]
		);				 
	
	function showDelete(id)
	{
		return "<input type='button' value='删除' class='x-btn button' onclick='doPowerBoxDelete(\"" + id  +   "\")'>";  
	}
	
	
	
	BTSDS = new Ext.data.Store({
				proxy: new Ext.data.DWRProxy(JBTSWeb.getBTSNewBOList, true),	
				reader: new Ext.data.ListRangeReader({
					totalProperty: 'totalSize',
					id: 'id'
				}, BTSType),
				sortInfo:{field:'id', direction:'ASC'}// 排序信息
			});

	
	var towerMountedGridDiv = Ext.get("mainTabPanelDIV");
	var BTSGrid = new Ext.grid.GridPanel({			 	
			ds: BTSDS,
			cm: BTSCM, 
			sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
                        rowselect: function(sm, row, rec) {
                            BTSFormPanel.getForm().loadRecord(rec);
                        }
                    }
                }),
			autoWidth : true,  
			autoScroll : true,  
			autoHeight　: false,
			region : 'center',
			height: 400,
			minSize: 200,		
			frame:true,
			collapsible:false, 
			enableDragDrop:false, 		
			bbar: new Ext.PagingToolbar({
					pageSize: 17,
					store: BTSDS,
					displayInfo: true,
					displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
					emptyMsg: "没有记录"
				})
		});

	BTSDS.on('load', function() {
		BTSGrid.getSelectionModel().selectFirstRow(); 
	});	
		
	var frequencyStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    }); 
	
	var frequencyCombo = new Ext.form.ComboBox({	   
		fieldLabel: '使用频段',
		name: 'frequency',	
		width:120,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'请选使用频段',
		emptyText:'选择使用频段',
		hiddenName:'frequency',
		triggerAction: 'all',
		allowBlank:false,
		editable:false, 
		disabled:true,
		store: frequencyStore
	});	
		
	frequencyStore.on('beforeload', function() {
			  frequencyStore.baseParams = {
					DIRECTORY_TYPE:'13'   
			  };
		});	
	frequencyStore.load({params:{DIRECTORY_TYPE:'13'}});
		 
		
	var primdevicetypeTStore = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    }); 
	
	var primdevicetypeTCombo = new Ext.form.ComboBox({	   
		fieldLabel: '设备类型',
		name: 'primdevicetype',	
		width:120,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'请选设备类型',
		emptyText:'选择设备类型',
		disabled:true,
		hiddenName:'primdevicetype',
		triggerAction: 'all',
		allowBlank:false,
		editable:false, 
		store: primdevicetypeTStore
	});	
	
	primdevicetypeTStore.on('beforeload', function() {
			  primdevicetypeTStore.baseParams = {
					DIRECTORY_TYPE:'37'   
			  };
		});	
	primdevicetypeTStore.load({params:{DIRECTORY_TYPE:'21'}});	
	
	
	BTSFormPanel = new Ext.form.FormPanel({
		region     : 'south', 
		bodyStyle  : 'padding: 10px; background-color: #DFE8F6',  
		height: 350,
		minSize: 350,
		maxSize: 400,
		frame:true, 	
		buttonAlign:'right',
		layout:'column', 
		items:[
			{
				layout:'column', 
				items:[
					 {
						columnWidth:.25,
						layout: 'form',  
						labelWidth:70,	
						labelAlign:'right',		
						items: [
							{
								xtype:'hidden',
								fieldLabel: '流水号',
								width:120,
								name: 'id'
							},{
								xtype:'textfield',
								readOnly: true,
								fieldLabel: '基站编号', 
								width:120,
								disabled:true,
								name: 'btscode'
							},{
								xtype:'textfield',
								readOnly: true,
								fieldLabel: '基站名称',
								width:120,
								disabled:true,
								name: 'btsname'
							},{
								xtype:'textfield',
								fieldLabel: '设备厂家',
								width:120,
								disabled:true,
								name: 'manufacturer',  
								allowBlank:false,
								blankText :'请输入设备厂家'	
							},
							primdevicetypeTCombo,
							{
								xtype:'textfield',
								fieldLabel: '基站配置',
								width:120,
								disabled:true,
								allowBlank:false,
								blankText :'请输入基站配置',	
								name: 'btscfg'
							},
							{
								xtype:'textfield',
								fieldLabel: '供电类型',
								width:120,
								disabled:true,
								blankText :'请输入供电类型',	
								name: 'powerType'
							}
							]
					 },
					 {
						columnWidth:.25,
						layout: 'form',  
						labelWidth:100,	 
						labelAlign:'right',	
						items: [
							frequencyCombo,
							{
								xtype:'textfield',
								fieldLabel: '2M电路使用情况',
								width:120,
								value:-1,
								disabled:true,
								name: 'ele2Mnum'
							}
							, 
							{
								xtype:'datefield',
								fieldLabel: '入网时间',
								format:'Y-m-d', 
								width:120,
								disabled:true,
								name: 'registtime',
								allowBlank:false,
								blankText :'请选择入网时间'	
							},
							{
								xtype:'textfield',
								fieldLabel: '天线型号',
								width:120,
								disabled:true,
								name: 'antennaType'
							},
							{
								xtype:'textfield',
								fieldLabel: '天线厂家',
								width:120,
								disabled:true,
								name: 'antennaFac'
							},
							{
								xtype:'numberfield',
								fieldLabel: '天线数量',
								width:120,
								value:-1,
								disabled:true,
								name: 'antennaNum'
							}
							]
					},
					{
						columnWidth:.25,
						layout: 'form',  
						labelWidth:100,	 
						labelAlign:'right',	
						items: [
							{
								xtype:'textfield',
								fieldLabel: '所属BSC',
								width:120,
								disabled:true,
								name: 'BSC'
							},
							{
								xtype:'textfield',
								fieldLabel: '天线增益', 
								width:120, 
								disabled:true,
								name: 'antennaGain'
							},
							{
								xtype:'textfield',
								fieldLabel: '天线方向性', 
								width:120, 
								disabled:true,
								name: 'antennaDirect'
							},
							{
								xtype:'textfield',
								fieldLabel: '天线极化方式', 
								width:120, 
								disabled:true,
								name: 'antennaPolar'
							},
							{
								xtype:'numberfield',
								fieldLabel: '天线挂高（米）', 
								width:120, 
								value:-1,
								disabled:true,
								decimalPrecision:2,
								name: 'antennaHeight'
							},
							{
								xtype:'textfield',
								fieldLabel: '天线美化方式', 
								width:120, 
								disabled:true,
								name: 'antennaPre'
							}]
					},
					{
						columnWidth:.25,
						layout: 'form',  
						labelWidth:100,	 
						labelAlign:'right',	
						items: [
								{
									xtype:'textfield',
									fieldLabel: '方向角',
									width:120,
									disabled:true,
									name: 'antennaAngle'
								},{
									xtype:'textfield',
									fieldLabel: '俯仰角',
									width:120,
									disabled:true,
									name: 'antennaPitchAngle'
								},{
									xtype:'textfield',
									fieldLabel: '其它信息1',
									width:120,
									disabled:true,
									name: 'other1'
								},{
									xtype:'textfield',
									fieldLabel: '其它信息2',
									width:120,
									disabled:true,
									name: 'other2'
								},{
									xtype:'textfield',
									fieldLabel: '其它信息3',
									width:120,
									disabled:true,
									name: 'other3'
								},{
									xtype:'textfield',
									fieldLabel: '其它信息4',
									width:120,
									disabled:true,
									name: 'other4'
								}
							]
					}
				]
			},
			{
				xtype:'tabpanel',
				plain:true,
				activeTab: 0,
				height:180, 
				//autoHeight:true,
				autoScroll:true,
				deferredRender: false,
				defaults:{bodyStyle:'padding:10px'},
				items:[
					{
						title:'900M/1800M',
						frame:true,
						autoHeight:true,
						layout:'column', 
						items:[
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:100,	
								height:180, 
								labelAlign:'right',			
								items: [
								        {
											xtype:'numberfield',
											fieldLabel: '机柜数量',
											name: 'cabinet',
											value:-1,
											disabled:true,
											width:120
										},{
											xtype:'numberfield',
											fieldLabel: '物理载频数量',
											name: 'frequencyNum',
											value:-1,
											disabled:true,
											width:120
										},{
											fieldLabel: '馈线型号',
											xtype:'textfield',
											name: 'feederType', 
											disabled:true,
											width:120
										}]
							 },{
									columnWidth:.25,
									layout: 'form',  
									labelWidth:70,	
									height:180, 
									labelAlign:'right',			
									items: [
									        {
												fieldLabel: '合路器型号',
												xtype:'textfield',
												name: 'combinerType',
												disabled:true,																	
												width:120
											},{
												xtype:'numberfield',
												fieldLabel: '合路器数量',
												name: 'combinerNum',
												disabled:true,
												value:-1,
												width:120
											}]
							},{
								columnWidth:.25,
								layout: 'form',  
								labelWidth:70,	
								height:180, 
								labelAlign:'right',			
								items: [
								        {
											fieldLabel: '主控板型号',
											xtype:'textfield',
											name: 'primContrmodel', 
											disabled:true,
											width:120
										},{
											xtype:'numberfield',
											fieldLabel: '主控板数量',
											name: 'primContrNum',
											disabled:true,
											value:-1,
											width:120
										}]
							 },{
									columnWidth:.25,
									layout: 'form',  
									labelWidth:70,	
									height:180, 
									labelAlign:'right',			
									items: [
									        {
												fieldLabel: '电源板型号',
												xtype:'textfield',
												disabled:true,
												name: 'powerPanelType', 
												width:120
											},{
												xtype:'numberfield',
												fieldLabel: '电源板数量',
												disabled:true,
												name: 'powerPanelNum',
												value:-1,
												width:120
											}]
							}
							 
						]
					},{
						title:'TD',
						frame:true,
						autoHeight:true,
						layout:'column', 
						items:[
							 {
								columnWidth:.25,
								layout: 'form',  
								labelWidth:100,	
								labelAlign:'right',	
								height:180, 								
								items: [
									{
										fieldLabel: '室内单元型号',
										xtype:'textfield',
										disabled:true,
										name: 'IDUType', 
										width:100
									}]
							 },{
									columnWidth:.25,
									layout: 'form',  
									labelWidth:100,	
									labelAlign:'right',	
									height:180, 								
									items: [
										{
											fieldLabel: '室内单元数量',
											xtype:'numberfield',
											disabled:true,
											name: 'IDUNum',
											value:-1,
											width:100
										}]
							},
							{
								columnWidth:.25,
								layout: 'form',  
								labelWidth:100,	
								labelAlign:'right',	
								height:180, 								
								items: [
									{
										fieldLabel: '室外单元型号',
										xtype:'textfield',
										disabled:true,
										name: 'ODUType', 
										width:100
									}]
							 },{
									columnWidth:.25,
									layout: 'form',  
									labelWidth:100,	
									labelAlign:'right',	
									height:180, 								
									items: [
										{
											fieldLabel: '室外单元数量',
											xtype:'numberfield',
											name: 'ODUNum',
											disabled:true,
											value:-1,
											width:100
										}]
							}
						]
					},{
						title:'备注',
						frame:true,
						//autoHeight:true,
						items:[
							{
								xtype:'textarea',
								fieldLabel: '备注',
								width:800,
								disabled:true,
								name: 'memo'
							}
						]
					}
					]
			}	 
			] 	
	});



	//Simple 'border layout' panel to house both grids
	
	var displayPanel = new Ext.Panel({
		width    : towerMountedGridDiv.getComputedWidth(),
		height   : 500,
		layout   : 'border',
		renderTo : 'BTSTab',
		items    : [
			BTSGrid,
			BTSFormPanel
		]
	});
	
	
	function saveBTS()
	{
		if (!BTSFormPanel.getForm().isValid())
			return;	
			
		var form = BTSFormPanel.getForm().getValues(false);	
		BTSBO = {};
		BTSBO.id = form.id;
		BTSBO.btsname = form.btsname;
		BTSBO.frequency = form.frequency;
		BTSBO.btscode = form.btscode;
		BTSBO.BSC = form.BSC;
		BTSBO.manufacturer = form.manufacturer;
		BTSBO.cabinet = form.cabinet;
		BTSBO.primdevicetype = form.primdevicetype;
		BTSBO.btscfg = form.btscfg;
		BTSBO.frequencyNum = form.frequencyNum;
		BTSBO.combinerType = form.combinerType;
		BTSBO.combinerNum = form.combinerNum;
		BTSBO.primContrmodel = form.primContrmodel;
		BTSBO.primContrNum = form.primContrNum;
		
		var nettingtimeDate = new Date();	
		var arrPlanTime = form.registtime.split("-");		
				
		var yearOth = arrPlanTime[0];
		var monthOth = arrPlanTime[1];
		var dayOth = arrPlanTime[2];
		nettingtimeDate.setFullYear(yearOth,monthOth-1,dayOth);
		
		BTSBO.registtime = nettingtimeDate;
		
		BTSBO.powerPanelType = form.powerPanelType;
		BTSBO.powerPanelNum = form.powerPanelNum;
		BTSBO.powerType = form.powerType;
		BTSBO.ele2Mnum = form.ele2Mnum;
		BTSBO.antennaType = form.antennaType;
		BTSBO.antennaFac = form.antennaFac;
		
		
		BTSBO.antennaNum = form.antennaNum;
		BTSBO.antennaGain = form.antennaGain;
		BTSBO.antennaDirect = form.antennaDirect;
		BTSBO.antennaPolar = form.antennaPolar;
		BTSBO.antennaHeight = form.antennaHeight;
		BTSBO.antennaPre = form.antennaPre;
		BTSBO.antennaAngle = form.antennaAngle;
		BTSBO.antennaPitchAngle = form.antennaPitchAngle;
		BTSBO.feederType = form.feederType;
		BTSBO.other1 = form.other1;
		BTSBO.other2 = form.other2;
		
		BTSBO.other3 = form.other3;
		BTSBO.other4 = form.other4;
		BTSBO.IDUType = form.IDUType;
		BTSBO.IDUNum = form.IDUNum;
		
		BTSBO.ODUType = form.ODUType;
		BTSBO.ODUNum = form.ODUNum;
		
		BTSBO.memo = form.memo;
		 
		JBTSWeb.saveBTSNewBO(BTSBO,function(data)
		{
			if(data)
			{ 
				Ext.Msg.alert('成功',"操作成功！"); 
				loadDate(BTSDS,BTSFormPanel);	 
			}else
			{
				Ext.Msg.alert("失败","操作失败!");
			}
		})
			
	}
	
	loadDate(BTSDS,BTSFormPanel);	
	
})

		



